package com.masterclient.app.modules.aftersale.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.bean.aftersale.AfterSaleItemBean;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.masterclient.app.R;
import com.masterclient.app.widget.PriceIntegralLayout;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

/**
 * 作者：sean
 * 创建时间：2017/8/4 17:24
 * 功能说明：
 */
public class AfterSaleServeAdapter extends BaseQuickAdapter<AfterSaleItemBean, BaseViewHolder> {

    private OnClickItemListener onClickItemListener;

    public AfterSaleServeAdapter(OnClickItemListener listener) {
        super(R.layout.item_after_sale_serve);
        this.onClickItemListener = listener;
    }

    @Override
    protected void convert(BaseViewHolder helper, AfterSaleItemBean item) {
        View viewItem = helper.getView(R.id.view_item);

        TextView tvExpressInfo = helper.getView(R.id.tv_express_info);
        TextView tvOrderStatus = helper.getView(R.id.tv_order_status);
        TextView tvAfterSaleType = helper.getView(R.id.tv_after_sale_type);
        TextView tvRefundTypeTitle = helper.getView(R.id.tv_refund_type_title);
        TextView tvRefundType = helper.getView(R.id.tv_refund_type);
        View viewRefundReason = helper.getView(R.id.view_refund_reason);
        TextView tvRefundReason = helper.getView(R.id.tv_refund_reason);
        LinearLayout viewProduct = helper.getView(R.id.view_product);

        tvExpressInfo.setText(String.format("退货编号 %s", item.refundNo));
        if ("4".equals(item.refundMode)){
            //保管
            tvOrderStatus.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.icon_bg_tag,0,0,0);
        }else if ("5".equals(item.refundMode)){
            //提货
            tvOrderStatus.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.icon_th_tag,0,0,0);
        }else {
            tvOrderStatus.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0);
        }
        tvOrderStatus.setText(item.refundStatusDesc);
        tvAfterSaleType.setText(item.refundTypeDesc);

        if ("0".equals(item.refundType)) {
            //退款
            viewRefundReason.setVisibility(View.GONE);
            tvRefundTypeTitle.setText("退款方式");
            tvRefundType.setText(item.payTypeDesc);
        } else if ("1".equals(item.refundType) || "3".equals(item.refundType)) {
            //退货退款
            viewRefundReason.setVisibility(View.VISIBLE);
            tvRefundTypeTitle.setText("收货状态");
            tvRefundType.setText(item.refundStatusDesc);
            tvRefundReason.setText(item.refundReason);
        }

        //商品信息
        if (item.product != null && item.product.size() > 0) {
            viewProduct.removeAllViews();
            for (int i = 0; i < item.product.size(); i++) {
                AfterSaleItemBean.ProductBean productBean = item.product.get(i);
                View view = View.inflate(mContext, R.layout.item_product_info, null);
                ImageView ivGood = view.findViewById(R.id.iv_good);
                TextView tvTitle = view.findViewById(R.id.tv_goods_title);
                TextView tvSku = view.findViewById(R.id.tv_skus);
                TextView tvApplyMoney = view.findViewById(R.id.tv_apply_money);
                PriceIntegralLayout llPrice = view.findViewById(R.id.ll_price);
                TextView tvNum = view.findViewById(R.id.tv_num);

                tvApplyMoney.setVisibility(View.VISIBLE);
                tvTitle.setText(productBean.title);
                tvNum.setText(String.format("×%s", productBean.num));
                tvSku.setText(productBean.spec);
                llPrice.setData("", productBean.refundAmount);
                ViewTransformUtil.glideImageView(mContext, productBean.image, ivGood,
                        new RoundedCornersTransformation(ScreenUtils.dp2px(7), 0),
                        R.mipmap.defaults, ScreenUtils.dp2px(107), ScreenUtils.dp2px(107));
                viewProduct.addView(view);
            }
            viewProduct.setVisibility(View.VISIBLE);
        } else {
            viewProduct.setVisibility(View.GONE);
        }
        viewItem.setOnClickListener(v -> onClickItemListener.clickItem(item.refundNo));
    }

    public interface OnClickItemListener {
        void clickItem(String id);
    }
}
